
    import java.util.HashMap;
    public class WordCount {
        public static void main(String[] args) {
            String[] words = {"no pains, no gains.", "well begun is half done.", "where there is a will, there is a way."};
            HashMap<String, Integer> wordCount = new HashMap<>();
            for (String word : words) {
                // 去除标点符号
                word = word.replaceAll("[^a-zA-Z ]", "").toLowerCase();
                // 按空格分割单词
                String[] wordArray = word.split("\\s+");
                for (String w : wordArray) {
                    // 如果单词已经在HashMap中，则将计数加1
                    if (wordCount.containsKey(w)) {
                        int count = wordCount.get(w);
                        wordCount.put(w, count + 1);
                    } else {
                        // 如果单词不在HashMap中，则添加该单词，并将计数设置为1
                        wordCount.put(w, 1);
                    }
                }
            }
            // 输出每个单词及其出现次数
            for (String key : wordCount.keySet()) {
                System.out.println(key + ": " + wordCount.get(key));
            }
        }
    }

